package com.zzz.algoritem;

/**
 * 最大值支持len*64
 */
public class Bitmap {


    private long max_value;
    private Long[] data;

    /**
     * @param len long数组长度 一个长度可以存64位
     */
    public Bitmap(int len) {
        max_value = ((long) len) << 6;
        data = new Long[len];
    }


    public void add(long l) {
        if (l > max_value) {
            throw new IllegalArgumentException("max value is " + max_value);
        }
        int index = (int) (l >> 6);
        int bitPos = (int) (l & 0x3f);
        if(data[index] == null)data[index]=0L;
        data[index] |= 1 << bitPos;
        System.out.println(Long.toBinaryString(data[index]));
    }

    public boolean contains(long l) {
        if (l > max_value) {
            throw new IllegalArgumentException("max value is " + max_value);
        }
        int index = (int) (l >> 6);
        int bitPos = (int) (l & 0x3f);

        return data[index]!=null &&  (data[index] >> bitPos & 1) == 1;
    }

    public static void main(String[] args) {
        Bitmap bitmap = new Bitmap(210000000);
        //bitmap.add(3200000000L);
        //System.out.println(bitmap.contains(3200000000L));
    }


}
